package cn.unknowpupil.domain.system;

import cn.unknowpupil.common.core.annotation.Excel;
import cn.unknowpupil.common.core.annotation.Excels;
import cn.unknowpupil.common.mybatis.base.SuperEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;


/**
 * Created at 2020-10-16 by  w10g <br>
 * Initialize SysUser  ... <br>
 * 用户信息表
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("sys_user")
@ApiModel(value = "SysUser 域", description = "管理员信息表")
public class SysUser extends SuperEntity<SysUser> {

    private static final long serialVersionUID = -1505053536669107618L;
    /**
     * 部门ID
     */
    @ApiModelProperty(value = "部门ID")
    @Excel(name = "部门ID")
    @TableField(value = "dept_id")
    private Long deptId;
    /**
     * 用户账号
     */
    @ApiModelProperty(value = "用户账号")
    @Excel(name = "用户账号")
    @TableField(value = "user_name")
    private String userName;
    /**
     * 用户昵称
     */
    @ApiModelProperty(value = "用户昵称")
    @Excel(name = "用户昵称")
    @TableField(value = "nick_name")
    private String nickName;
    /**
     * 用户类型（00系统用户）
     */
    @ApiModelProperty(value = "用户类型（00系统用户）")
    @Excel(name = "用户类型（00系统用户）")
    @TableField(value = "user_type")
    private String userType;
    /**
     * 用户邮箱
     */
    @ApiModelProperty(value = "用户邮箱")
    @Excel(name = "用户邮箱")
    @TableField(value = "email")
    private String email;
    /**
     * 手机号码
     */
    @ApiModelProperty(value = "手机号码")
    @Excel(name = "手机号码")
    @TableField(value = "phonenumber")
    private String phonenumber;
    /**
     * 用户性别（0男 1女 2未知）
     */
    @ApiModelProperty(value = "用户性别（0男 1女 2未知）")
    @Excel(name = "用户性别（0男 1女 2未知）")
    @TableField(value = "sex")
    private String sex;
    /**
     * 头像地址
     */
    @ApiModelProperty(value = "头像地址")
    @Excel(name = "头像地址")
    @TableField(value = "avatar")
    private String avatar;
    /**
     * 密码
     */
    @ApiModelProperty(value = "密码")
    @Excel(name = "密码")
    @TableField(value = "password")
    @JsonIgnore
    @JsonProperty
    private String password;
    /**
     * 最后登录IP
     */
    @ApiModelProperty(value = "最后登录IP")
    @Excel(name = "最后登录IP")
    @TableField(value = "login_ip")
    private String loginIp;
    /**
     * 最后登录时间
     */
    @ApiModelProperty(value = "最后登录时间")
    @Excel(name = "最后登录时间")
    @TableField(value = "last_login_date")
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    private Date last_LoginDate;
    /**
     * 部门对象
     */
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Excel.Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Excel.Type.EXPORT)
    })
    @ApiModelProperty(value = "部门对象")
    @TableField(exist = false)
    private SysDept dept;

    /**
     * 角色对象
     */
    @ApiModelProperty(value = "角色对象")
    @TableField(exist = false)
    private List<SysRole> roles;

    /**
     * 角色组
     */
    @ApiModelProperty(value = "角色组")
    @TableField(exist = false)
    private Long[] roleIds;

    /**
     * 岗位组
     */
    @ApiModelProperty(value = "岗位组")
    @TableField(exist = false)
    private Long[] postIds;

    public boolean isAdmin() {
        return isAdmin(this.getId());
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }


}